/*
 * @Author: zhangfeng
 * @Date: 2022-09-06 16:02:42
 * @LastEditTime: 2023-12-29 17:10:27
 * @LastEditors: zhangfeng
 * @Description:
 * @FilePath: \nodeapi\src\router\user.router.js
 * © 2023 张峰，All rights reserved.
 */
const Router = require("koa-router");

const {
  register,
  login,
  resetPassword,
  getUserInfo,
  getUserListAll,
  deleteUsers,
  updateUser,
} = require("../controller/user.controller");
const {
  userValidator,
  verifyUser,
  bcryptPassword,
  verifyLogin,
  bindRoleUser,
  getRoleUser,
  registerReturn,
} = require("../middleware/user.middleware");
const { auth } = require("../middleware/auth.middleware");
const {
  getPremissionByRoleId,
} = require("../middleware/role-premission.middleware");
// 路由前缀
const router = new Router({ prefix: "/users" });

// 注册 userValidator(合法性) verifyUser（合理性）
router.post(
  "/register",
  userValidator,
  verifyUser,
  bcryptPassword,
  register,
  bindRoleUser,
  getRoleUser,
  registerReturn
);

// 登录

router.post("/login", userValidator, verifyLogin, login);

// 获取个人信息
router.get(
  "/getUserInfo",
  auth,
  getRoleUser,
  getPremissionByRoleId,
  getUserInfo
);

router.get("/", getUserListAll);

router.post("/refresh");

// 修改密码
router.patch("/password", auth, bcryptPassword, resetPassword);

// 修改密码
router.patch("/", updateUser);

router.delete("/", deleteUsers);

module.exports = router;
